package com.lifeonwalden.game.mindustry.entity;

import com.lifeonwalden.game.mindustry.constant.Gate;
import com.lifeonwalden.game.mindustry.constant.PorterType;
import com.lifeonwalden.game.mindustry.constant.ResourceType;
import com.lifeonwalden.game.mindustry.feature.Export;

import java.util.Optional;

public class StaticEntity extends Surface implements Export {
    public void tryJoin(Gate at, Gate to, StaticEntity unit) {
        PorterType porter = unit.porterAt(to);
        switch (this.porterAt(at)) {
            case EXPORTER: {
                if (PorterType.TAKER == porter || PorterType.BIDIRECTIONAL == porter) {
                    unit.joinExporter(this, to);
                    this.join(unit, at);
                }
                break;
            }
            case TAKER: {
                if (PorterType.EXPORTER == porter || PorterType.BIDIRECTIONAL == porter) {
                    this.joinExporter(unit, at);
                    unit.join(this, to);
                }
                break;
            }
            case BIDIRECTIONAL: {
                switch (porter) {
                    case EXPORTER: {
                        this.joinExporter(unit, at);
                        unit.join(this, to);
                        break;
                    }
                    case TAKER: {
                        unit.joinExporter(this, to);
                        this.join(unit, at);
                        break;
                    }
                }
                break;
            }
        }
    }

    public void joinExporter(StaticEntity unit, Gate at) {
    }

    public void join(StaticEntity unit, Gate at) {
    }

    public void unjoin(Gate at) {
    }

    public PorterType porterAt(Gate gate) {
        return PorterType.TAKER;
    }

    @Override
    public Optional<ResourceType> take() {
        return Optional.empty();
    }

    @Override
    public Optional<ResourceType> checkResourceAcceptable() {
        return Optional.empty();
    }
}
